window.onload = function () {
    $.extend(String.prototype, {
        substitute: function (data) {
            if (data && typeof (data) == 'object') {
                return this.replace(/\{([^{}]+)\}/g, function (match, key) {
                    var value = data[key];
                    return (value !== undefined) ? '' + value : '';
                });
            } else {
                return this.toString();
            }
        },
    })

    console.log(1)
    var $navBa = $('.head_nav a')
    var $navBa2 = $('.head_nav2 a')
    var $nav = $('.head_nav')
    var $nav2 = $('.head_nav2')
    var $menuBtn = $('.stone_head .menu_icon')


    $('.nav_img').click(function () {
        $("body,html").animate({
            scrollTop: 0 //让body的scrollTop等于pos的top，就实现了滚动 
        }, 500, 'swing');
    })

    $menuBtn.click(function () {
        $nav2.slideToggle("slow");
    })
    $navBa.click(function () {
        var activeAttr = $(this).attr('data-id')
        var acHref = $(this).attr('href')
        if (activeAttr && activeAttr == 'list') {
            goList()
        } else {
            goHome(acHref)
        }
    })
    $navBa2.click(function () {
        var activeAttr = $(this).attr('data-id')
        var acHref = $(this).attr('href')
        if (activeAttr && activeAttr == 'list') {
            goList()
        } else {
            goHome(acHref)
        }
        $menuBtn.show()
        $nav2.hide()
    })
    function changeState() {
        var bodyScrollTop = $(document).scrollTop();
        if ($(document).width() > 750) {
            if (bodyScrollTop >= 35) {
                showWhite()
            } else {
                hideWhite()
            }
        }
    }
    function showWhite() {
        $('.nav_box').addClass("nav_box_white")
        $('.nav_img2').show()
        $('.nav_img1').hide()
    }
    function hideWhite() {
        $('.nav_img2').hide()
        $('.nav_img1').show()
        $('.nav_box').removeClass("nav_box_white")
    }
    function goHome(activeAttr) {

        window.location.href = "./index.html" + activeAttr;
    }
    function goList() {
        window.location.href = "./list.html";
    }
    window.onresize = function () {
        if ($(document).width() > 750) {
            changeState()
        } else {
            $('.nav_img2').show()
            $('.nav_img1').hide()
            if ($nav2.is(":hidden")) {
                $menuBtn.show()
            }
        }
    }
    window.onscroll = function () {
        changeState()
    }
  
    var $ul = $('.new_list')
  
    var newList = [
        {
            id: '1',
            title: '新闻标题',
            date: '2018.01.09',
            msg: '高校拔尖人才设立的高额奖学金，旨在发掘、高校拔尖人才设立的高额奖学金，旨在发掘、高校拔尖人才设立的高额奖学金，旨在发掘、高校拔尖人才设立的高额奖学金，旨在发掘、高校拔尖人才设立的高额奖学金，旨在发掘、高校拔尖人才设立的高额奖学金，旨在发掘、',
            imgUrl: 'https://www.sensetime.com/data/upload/thumbnail/2018-08-03/69be714b6ad9cbd345283d347a00dff9_591_445.png'
        }
    ]
    var tmpList = [
        '<li>',
        '<div class="left">',
        '<div class="title">',
        ' <a href="#" class="ellipsis">{title} </a>',
        ' <span class="date">{date}</span>',
        '</div>',
        ' <div class="msg ellipsis3">{msg}</div>',
        '</div>',
        '<div class="right">',
        '<img src="{imgUrl}" alt="">',
        '</div>',
        '</li>'
    ].join('')
    var pageIndex=10

    var filUL = function filUL() {
        var $li = tmpList.substitute(newList[0])
  
        $ul.append($li)
        var $liBox = $('.new_list li')

       
   
        $liBox.find('img').hover(function () {
            var Rimg = $(this)
            Rimg.css({
                transform: 'scale(1.2)'
            })
        }, function () {
            var Rimg = $(this)
            Rimg.css({
                transform: 'scale(1)'
            })
        })

    }
    var initUL = function initUL() {
        $ul.html('')
        getlist(pageIndex)
    }
    var getlist = function getlist(page) {
        for(var i=0;i<page;i++){
            filUL()
        }
    }
    var _loadMore=function _loadMore(){
        pageIndex=pageIndex+10
        getlist(pageIndex)
    }
    initUL()
    $(function () {
        $(window).scroll(function () {
            if ((100 + $(window).scrollTop()) >= ($(document).height() - $(window).height())) {
                _loadMore()
            }
        });
    });

}